/**
 * 
 */
package pl.kaczanowscy.tomek.ipdl;

import java.util.HashMap;
import java.util.Map;

/**
 * Implementation of {@link GameResult} for two players game.
 * 
 * @author Tomek Kaczanowski
 * 
 */
public final class GameResultImpl implements GameResult {

	private static final Integer BEGIN_PAYOFF = 0;
	private Map<Strategy, Integer> payoff;

	// should I have a generic constructor for n-players game ?
	/**
	 * Remembers strategies that play the game.
	 * 
	 * @param sA
	 *            first strategy
	 * @param sB
	 *            second strategy
	 */
	public GameResultImpl(Strategy sA, Strategy sB) {
		payoff = new HashMap<Strategy, Integer>(2);
		payoff.put(sA, BEGIN_PAYOFF);
		payoff.put(sB, BEGIN_PAYOFF);
	}

	// TODO what if asked about other strategy - is null ok or should throw an
	// exception ?
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.GameResult#getPayoff(pl.kaczanowscy.tomek.ipdl
	 * .Strategy)
	 */
	@Override
	public int getPayoff(Strategy strategy) {
		return payoff.get(strategy);
	}

	// TODO what if asked about other strategy - is null ok or should throw an
	// exception ?
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.GameResult#addPayoff(pl.kaczanowscy.tomek.ipdl
	 * .Strategy, int)
	 */
	@Override
	public void addPayoff(Strategy strategy, int payoffToAdd) {
		int currentPayoff = payoff.get(strategy);
		payoff.put(strategy, currentPayoff + payoffToAdd);

	}

}
